package com.kj.xuyuan.util;

import android.content.Context;
import android.content.SharedPreferences;
import com.kj.xuyuan.base.Constants;

/**
 * 对SharedPreference文件中的各种类型的数据进行存取操作
 */
public class SPUtils {

    public static boolean getBooleanData(Context context, String key) {
        SharedPreferences sp = context.getSharedPreferences(Constants.SP_NAME, Context.MODE_PRIVATE);
        return sp.getBoolean(key,false);
    }

    public static void setBooleanData(Context context, String key, boolean value) {
        SharedPreferences sp = context.getSharedPreferences(Constants.SP_NAME, Context.MODE_PRIVATE);
        sp.edit().putBoolean(key,value).commit();
    }

    public static void setStringData(Context context, String key,String value) {
        SharedPreferences sp = context.getSharedPreferences(Constants.SP_NAME, Context.MODE_PRIVATE);
        sp.edit().putString(key,value).commit();
    }

    public static String getStringData(Context context, String key,String defaultValue) {
        SharedPreferences sp = context.getSharedPreferences(Constants.SP_NAME, Context.MODE_PRIVATE);
        return sp.getString(key,defaultValue);
    }

    public static void setIntData(Context context, String key,int value) {
        SharedPreferences sp = context.getSharedPreferences(Constants.SP_NAME, Context.MODE_PRIVATE);
        sp.edit().putInt(key,value).commit();
    }

    public static int getIntData(Context context, String key,int defaultValue) {
        SharedPreferences sp = context.getSharedPreferences(Constants.SP_NAME, Context.MODE_PRIVATE);
        return sp.getInt(key,defaultValue);
    }
}